package com.hua.yuan.view.player;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.hua.yuan.R;


/**
 * Created by Ted on 2015/8/4.
 * MediaController
 */
public class MediaToolbar extends FrameLayout implements View.OnClickListener {

    private MediaToolbarImpl mMediaToolbarImpl;
    public ImageView mMoreBtn;
    public ImageView mBackBtn;
    private TextView mTitle;

    @Override
    public void onClick(View view) {

        if (view.getId() == R.id.menu_more) {
            mMediaToolbarImpl.onMoreSetting();
        } else if (view.getId() == R.id.back_pl) {
            mMediaToolbarImpl.onBack();
        }
    }

    public void showMore(boolean flag) {
        if (mMoreBtn != null) {
            if (flag) {
                mMoreBtn.setVisibility(VISIBLE);
            } else {
                mMoreBtn.setVisibility(INVISIBLE);
            }
        }

    }


    public void setMediaControl(MediaToolbarImpl mediaControl) {
        mMediaToolbarImpl = mediaControl;
    }

    public MediaToolbar(Context context) {
        super(context);
        initView(context);
    }

    public MediaToolbar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    public MediaToolbar(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    private void initView(Context context) {
        View.inflate(context, R.layout.biz_video_media_toolbar, this);

        mMoreBtn = findViewById(R.id.menu_more);
        mBackBtn = findViewById(R.id.back_pl);
        mTitle = findViewById(R.id.title);

        mMoreBtn.setOnClickListener(this);
        mBackBtn.setOnClickListener(this);
        initData();
    }

    private void initData() {

        mMoreBtn.setVisibility(INVISIBLE);

    }

    public void udpateTitle(String title) {
        if (mTitle != null) {
            mTitle.setText(title);
        }
    }


    public interface MediaToolbarImpl {

        void onMoreSetting();

        void onBack();
    }

}
